package com.alvin.demo.common;

import lombok.Data;

@Data
public class R{

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private Object data; //数据

    public static R ok(Object data) {
        R r = new R();
        r.setCode(200);
        if(data instanceof String){
            r.setMsg(data.toString());
        }else{
            r.setMsg("操作成功！！");
            r.setData(data);
        }
        return r;
    }

    public static R ok( String msg, Object data ) {
        R r = new R();
        r.setCode(200);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }

    public static R error(String msg) {
        R r = new R();
        r.setCode(500);
        r.setMsg(msg);
        return r;
    }

    public static R error( Integer code , String msg) {
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

}
